package com.muqi.app.qlearn.student.ui;

import java.util.ArrayList;
import java.util.List;

import com.muqi.app.im.adapter.MyFragmentPagerAdapter;
import com.muqi.app.qlearn.fragments.BannerFragment;
import com.muqi.app.qlearn.fragments.HomeWorkFragment;
import com.muqi.app.qlearn.fragments.NotificationFragment;
import com.muqi.app.qlearn.student.BaseFragmentActivity;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.qlearn.student.R.id;
import com.muqi.app.qlearn.student.R.layout;
import com.muqi.app.qlearn.student.R.menu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class HwAndNotificationActivity extends BaseFragmentActivity implements
		OnClickListener {
	private TextView o2oButton;
	private TextView classButton;
	private ViewPager orderPager;
	private MyFragmentPagerAdapter mAdapter;
	private List<Fragment> fragmentList = new ArrayList<Fragment>();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_hw_and_notification);
	}
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		mSpUtil.setNotification(mSpUtil.getCurrentChildId() + "h",
				0);
		mSpUtil.setNotification(mSpUtil.getCurrentChildId() + "n",
				0);
		sendBroadcast(new Intent(BannerFragment.BANNER_HOME_CHANGED));
	}

	@Override
	protected void onInit() {
		o2oButton = (TextView) findViewById(R.id.one2one_button);
		o2oButton.setOnClickListener(this);
		classButton = (TextView) findViewById(R.id.class_button);
		classButton.setOnClickListener(this);
		orderPager = (ViewPager) findViewById(R.id.order_content);

	}

	@Override
	protected void onData() {
		fragmentList.add(new HomeWorkFragment());
		fragmentList.add(new NotificationFragment());
		mAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),
				fragmentList);
		orderPager.setAdapter(mAdapter);
		orderPager.addOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				classButton
						.setBackgroundResource(R.drawable.corners_white_5_radus);
				o2oButton
						.setBackgroundResource(R.drawable.corners_white_5_radus);
				classButton
						.setTextColor(getResources().getColor(R.color.white));
				o2oButton.setTextColor(getResources().getColor(R.color.white));
				switch (position) {
				case 0:
					classButton
							.setBackgroundResource(R.drawable.corners_right_bg);
					o2oButton.setTextColor(getResources().getColor(
							R.color.green));
					break;
				case 1:
					o2oButton.setBackgroundResource(R.drawable.corners_left_bg);
					classButton.setTextColor(getResources().getColor(
							R.color.green));
					break;
				}

			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}
		});

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.one2one_button:
			orderPager.setCurrentItem(0);
			break;
		case R.id.class_button:
			orderPager.setCurrentItem(1);
			break;
		default:
			break;
		}

	}

	public void onBack(View v) {
		finish();
	}

}
